package com.tvb.pojo;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang.builder.ToStringBuilder;
@Entity
@Table(name="login_user")
public class LoginUser {
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private Integer id;
	
	@Column(name="account")
	private String account;//账户
	
	@Column(name="password")
	private String password;//密码
	
	@Column(name="name")
	private String name;//名称
	
	//级联
	@ManyToMany(cascade={CascadeType.REMOVE},fetch=FetchType.LAZY)
	@JoinTable(name="login_user_role",
		joinColumns={@JoinColumn(name="user_id",referencedColumnName="id")},
		inverseJoinColumns = {@JoinColumn(name="role_code",columnDefinition="role_code")})
	private Set<LoginRole> roles = new HashSet<LoginRole>();
	
	@Transient
	private Set<Integer> roleCodes = new HashSet<Integer>();
	
	public Set<Integer> getRoleCodes() {
		return roleCodes;
	}
	public void setRoleCodes(Set<Integer> roleCodes) {
		this.roleCodes = roleCodes;
	}
	public Set<LoginRole> getRoles() {
		return roles;
	}
	public void setRoles(Set<LoginRole> roles) {
		this.roles = roles;
	}
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getAccount() {
		return account;
	}
	public void setAccount(String account) {
		this.account = account;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this);
	}
}
